﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace WebApp.Controllers
{
    public class NgflowController : Controller
    {

        private static readonly string SAVE_PATH = @"D:\upload\test";

        // GET: Ngflow
        public ActionResult Index()
        {
            return View();
        }


        public JsonResult Uploader()
        {
            var files = this.Request.Files;
            if (files == null || files.Count == 0)
            {
                return Json(null);
            }
            if (!System.IO.Directory.Exists(SAVE_PATH))
            {
                Directory.CreateDirectory(SAVE_PATH);
            }
            IList<string> listFileName = new List<string>(files.Count);
            foreach (string item in files.AllKeys)
            {
                HttpPostedFileBase postedFile = files[item] as HttpPostedFileBase;
                if (postedFile == null)
                {
                    continue;
                }

                string extendName = Path.GetExtension(postedFile.FileName);
                string fileName = String.Concat(Guid.NewGuid(), extendName);
                string savePath = Path.Combine(SAVE_PATH, fileName);
                postedFile.SaveAs(savePath);
                listFileName.Add(fileName);
            }

            return Json(listFileName);

        }
    }
}